package com.note.mq.service;

import com.note.mq.entity.MsgData;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * mq 发送消息接口
 */
public interface MqSendMsgI {

    void sendMsg(MsgData msgData);

    /**
     * 对象转化为字节码
     * @param obj
     * @return
     * @throws Exception
     */
   default  byte[] getBytesFromObject(Serializable obj) throws Exception {
        if (obj == null) {
            return null;
        }
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(bo);
        oo.writeObject(obj);
        return bo.toByteArray();
    }
}
